﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

namespace sdamarketing
{
    public partial class Interesi : osnova1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    if (Session["idUser"] == null)
                    {
                        Response.Redirect("~/Default.aspx");
                    }
                    else
                    {
                        string ajdiNaUser = Session["idUser"].ToString();
                        DataSet interes = ReturnDataSet.ReturSet("SELECT idOblastNaInteres, KoeficientNaInteres, idUser FROM Interesi WHERE (idUser = '" + Session["idUser"].ToString() + "') ORDER BY idOblastNaInteres");
                        if (interes.Tables["DataSet"].Rows.Count > 0)
                        {
                            avtoslider.Text = interes.Tables["DataSet"].Rows[0].ItemArray[1].ToString();
                            oruzjeslider.Text = interes.Tables["DataSet"].Rows[1].ItemArray[1].ToString();
                            computerslider.Text = interes.Tables["DataSet"].Rows[2].ItemArray[1].ToString();
                            foodslider.Text = interes.Tables["DataSet"].Rows[3].ItemArray[1].ToString();
                            drinksslider.Text = interes.Tables["DataSet"].Rows[4].ItemArray[1].ToString();
                            electronicsslider.Text = interes.Tables["DataSet"].Rows[5].ItemArray[1].ToString();
                            fashionslider.Text = interes.Tables["DataSet"].Rows[6].ItemArray[1].ToString();
                            phoneslider.Text = interes.Tables["DataSet"].Rows[7].ItemArray[1].ToString();
                            musicslider.Text = interes.Tables["DataSet"].Rows[8].ItemArray[1].ToString();
                            moviesslider.Text = interes.Tables["DataSet"].Rows[9].ItemArray[1].ToString();
                        }
                        else
                        {
                            avtoslider.Text = "0";
                            oruzjeslider.Text = "0";
                            computerslider.Text = "0";
                            foodslider.Text = "0";
                            drinksslider.Text = "0";
                            electronicsslider.Text = "0";
                            fashionslider.Text = "0";
                            phoneslider.Text = "0";
                            musicslider.Text = "0";
                            moviesslider.Text = "0";
                            lblTest.Text = "Немате покажано никаков интерес за групите";
                        }

                    }
                }
                catch (SqlException exception)
                {
                    lblTest.Text = "Грешка обидетесе повторно";
                    SendToLogFile.SendRecordToFIle(DateTime.Now.ToString() + " -exc- " + exception.Message.ToString() + " -stackTrace- " + exception.StackTrace.ToString());
                }
            }
        }

        protected void btnInteres_Click(object sender, EventArgs e)
        {
            try
            {
                int ajdiNaUser = Int32.Parse(Session["idUser"].ToString());

                Zainteresiranost.EditInteresi(1, Int32.Parse(avtoslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(2, Int32.Parse(oruzjeslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(3, Int32.Parse(computerslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(4, Int32.Parse(foodslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(5, Int32.Parse(drinksslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(6, Int32.Parse(electronicsslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(7, Int32.Parse(fashionslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(8, Int32.Parse(phoneslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(9, Int32.Parse(musicslider.Text), ajdiNaUser);
                Zainteresiranost.EditInteresi(10, Int32.Parse(moviesslider.Text), ajdiNaUser);

                lblTest.Text = "Успешно се регистрирани вашите интереси.";
            }
            catch (SqlException exception)
            {
                lblTest.Text = "Грешка обидетесе повторно";
                SendToLogFile.SendRecordToFIle(DateTime.Now.ToString() + " -exc- " + exception.Message.ToString() + " -stackTrace- " + exception.StackTrace.ToString());
            }
        }
    }
}
